package com.lc202310;

import java.util.Arrays;

/**
 * Description:
 *
 * @Create 2023/10/11 13:27
 * @Version 1.0
 */
public class Solution2731 {
    //    拆分成一小段，一小段相加 1*(length-1)N1 +2*(length-2)N2
    public int sumDistance(int[] nums, String s, int d) {
        int length = nums.length;
        for (int i = 0; i < length; i++) {
            if (s.charAt(i) == 'R') {
                nums[i] += d;
                continue;
            }
            nums[i] -= d;
        }
        Arrays.sort(nums);
        long res = 0;
        // 特别注意long和int长度溢出
        for (int i = 1; i < length; i++) {
            res += (((long) nums[i] - nums[i - 1]) % 1000000007) * ((long) i * (length - i) % 1000000007) % 1000000007;
            res = res % 1000000007;
        }
        return (int) res;
    }
}
